package com.xdjk.networkdemo.net;

import com.xdjk.networkdemo.entity.Principal;
import com.xdjk.networkdemo.net.bean.BaseResponse;
import com.xdjk.networkdemo.net.bean.WeatherData;

import java.util.List;
import java.util.Map;

import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.http.Body;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.Header;
import retrofit2.http.Multipart;
import retrofit2.http.POST;
import retrofit2.http.Part;
import retrofit2.http.Path;
import retrofit2.http.QueryMap;
import retrofit2.http.Streaming;
import retrofit2.http.Url;
import rx.Observable;

/**
 * Created by zhanghs on 2017/8/16.
 */

public interface HttpService {
    /**
     * 获取数据
     *
     * @return
     */
    @GET("data/cityinfo/{cityId}.html")
    Observable<WeatherData> getWeatherData(@Path("cityId") String cityId);
    /**
     * 获取数据
     *
     * @return
     */
    @GET("data/forecast/{cityId}.html?_=1381891660081")
    Observable<WeatherData> getWeatherDataByCode(@Path("cityId") String cityId);

    //上传图片和描述
    @Multipart
    @POST("UploadFileServer/servlet/UploadHandleServlet")
    abstract Observable<String> uploadUserFile(
            @Part("description") RequestBody description,
            @Part("file\"; filename=\"image.png\"") RequestBody img
    );
    //上传图片和描述
    @Multipart
    @POST("UploadFileServer/servlet/UploadHandleServlet")
    abstract Observable<String> uploadUserFile(
            @Part("description") String description,
            @Part("file\"; filename=\"image.png\"") RequestBody img
    );

    //上传图片和图片描述，图片类型，用户id等其它信息
    //如果除了图片外还需要传递其它信息，只需要增加几个@Part就可以了。
    @Multipart
    @POST("上传的地址")
    Observable<String> uploadUserFileAndId(
            @Part("describe") String describe,
            @Part("type") String type,
            @Part("userid") String userid,
            @Part("fileName") RequestBody description,
            @Part("file\"; filename=\"image.png\"") RequestBody img
    );
    /**
     * 通过 List<MultipartBody.Part> 传入多个part实现多文件上传
     * @param parts 每个part代表一个
     * @return 状态信息
     */
    @Multipart
    @POST("users/image")
    Observable<BaseResponse<String>> uploadFilesWithParts(@Part() List<MultipartBody.Part> parts);
    /**
     * 通过 MultipartBody和@body作为参数来上传
     * @param multipartBody MultipartBody包含多个Part
     * @return 状态信息
     */
    @POST("UploadFileServer/servlet/UploadHandleServlet")
    Observable<BaseResponse<String>> uploadFileWithRequestBody(@Body MultipartBody multipartBody);

    @Multipart
    @POST
    Observable<ResponseBody> uploadFile(@Url String url,@Part MultipartBody.Part file);

    @Multipart
    @POST("{url}")
    Observable<ResponseBody> upLoadFile(
            @Path("url") String url,
            @Part("image\"; filename=\"image.jpg") RequestBody requestBody);

    @Multipart
    @POST("upload/singleUpload")
    Observable<ResponseBody> uploadFile(@Part MultipartBody.Part filepart,@Part MultipartBody.Part textPart);

    /*断点续传下载接口*/
    @Streaming/*大文件需要加入这个判断，防止下载过程中写入到内存中*/
    @GET
    Observable<ResponseBody> download(@Header("RANGE") String start, @Url String url);
    /**
     *  登陆验证
     * @return
     */
    @FormUrlEncoded
    @POST("ssms/a/login")
    Observable<BaseResponse<Principal>> loginTest(@Field("username") String username,
                                                  @Field("password") String password,
                                                  @Field("mobileLogin") String mobileLogin,
                                                  @Field("rememberMe") boolean rememberMe);

    /**
     * 登陆验证
     *
     * @return
     */
    @POST("ssms/a/login")
    Observable<BaseResponse<Principal>> loginTest2(@QueryMap Map<String, String> params);
}
